package com.styytech.dadabao.api.requestresult;

import android.util.Log;

import com.styytech.dadabao.api.response.AbstractResponseResult;
import com.styytech.dadabao.bean.RecommendProduct;
import com.styytech.dadabao.utils.ParseJsonUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by User on 2015/8/3.
 */
public class RecommendProductResult extends RequestResult {
    /**
     * 构造函数
     *
     * @param httpResponseResult
     */
    int httpType;
    // 项目名称:
    String productName;
    //  年化收益率:
    String expectedReturnRatio;
    // 项目期限:
    String timeLimit;
    //  项目规模:
    int totalCredit;
    // 已售金额:
    int progress;
    RecommendProduct recommendProduct = new RecommendProduct();

    public RecommendProductResult(AbstractResponseResult httpResponseResult) {
        super(httpResponseResult);

    }

    @Override
    public void doBusiness() {
        super.doBusiness();
        if (super.isSuccess()) {
            dataParse((JSONArray) super.getRows());
        }
    }

    private void dataParse(JSONArray jsonArray) {

        JSONObject jsonObjectApp;

        try {
            if (jsonArray.length() > 0) {
                Log.e("adsas", "" + jsonArray);
                jsonObjectApp = jsonArray.getJSONObject(0);

                recommendProduct = ParseJsonUtils.dataParseProduct(jsonObjectApp);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        if (httpResponseResult != null) {
            httpResponseResult.executeSuccess(recommendProduct);
        }
    }


}
